package com.wxq.workpad.finishproduct

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
import com.samluys.statusbar.StatusBarUtils
import com.wxq.workpad.adapter.MainFragmentAdapter
import com.wxq.workpad.adapter.TopTitleAdapter
import com.wxq.workpad.base.BaseActivity
import com.wxq.workpad.base.RealShow
import com.wxq.workpad.databinding.ActivityProductTestDetailBinding
import com.wxq.workpad.entity.TopTitleEntity
import com.wxq.workpad.lailiao.LaiLiaoFragment
import com.wxq.workpad.lailiao.LaiLiaoFragmentAdapter

class ProductTestDetailActivity:  BaseActivity<ActivityProductTestDetailBinding>(){

    private lateinit var fragments: MutableList<Fragment>
    private lateinit var tabTitles: MutableList<String>
    override fun initData() {
        val id = intent.getStringExtra("id")
        showToast(id.toString())
        tabTitles = ArrayList()
        tabTitles.add("基础信息")
        tabTitles.add("问题点登记")
        tabTitles.add("调试动作书")
        tabTitles.add("校线表")
        fragments = ArrayList()
        fragments.add(BaseInfoFragment.newInstance(id!!))
        fragments.add(QuestionFragment.newInstance(id!!))
        fragments.add(TestActionFragment.newInstance(id!!))
        fragments.add(XiaoXianFragment.newInstance(id!!))
        binding.viewpager.offscreenPageLimit = 3
        binding.viewpager.adapter =
            LaiLiaoFragmentAdapter(supportFragmentManager, fragments, tabTitles)
        binding.viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {

            }

            override fun onPageSelected(position: Int) {
                if (fragments.get(position) is RealShow) {
                    (fragments.get(position) as RealShow).realShow()
                }
            }

            override fun onPageScrollStateChanged(state: Int) {

            }

        })
        binding.tabLayout.setTabMode(TabLayout.MODE_FIXED)
        binding.tabLayout.setupWithViewPager(binding.viewpager)
        binding.tabLayout.setTabsFromPagerAdapter(binding.viewpager.adapter)


        binding.viewpager.setCurrentItem(0)
        if (fragments.get(0) is RealShow) {
            (fragments.get(0) as RealShow).realShow()
        }
        binding.ivBack.setOnClickListener {
            onBackPressed()
        }
    }

    override fun initView(instanceState: Bundle?) {
        StatusBarUtils.transparencyBar(this@ProductTestDetailActivity)
        StatusBarUtils.StatusBarIconDark(this@ProductTestDetailActivity)

    }


    companion object {

        @JvmStatic
        fun naveToActivity(context: Context, id: String ) {
            val intent = Intent(context, ProductTestDetailActivity::class.java)
            intent.putExtra("id",id)
            context.startActivity(intent)
        }
    }
}